package richbar.com.richbar.fragment.product;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;

import com.common.base.BaseFragment;
import com.common.util.LogUtil;

import richbar.com.richbar.R;
import richbar.com.richbar.util.NetWorkUtil;

/**
 * Created by QiYang on 2018/11/27.
 */

public class ProductDetailsFragment extends BaseFragment {
    public WebView wv_detail;
    private WebSettings webSettings;
    public static ProductDetailsFragment newInstance(String id){
        ProductDetailsFragment fragment = new ProductDetailsFragment();
        Bundle bundle = new Bundle();
        bundle.putString("id",id);
        fragment.setArguments(bundle);
        return fragment;
    }

    @Override
    protected View onCreate(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_product_details,container,false);
        wv_detail = view.findViewById(R.id.wv_detail);
        LogUtil.e("AADADWDAWD","1111");
        return view;
    }

    @Override
    protected void initData() {
        String id = getArguments().getString("id");
        String url = NetWorkUtil.URL + "/home/goods/detail?gid=" + id;
        //声明WebSettings子类
        WebSettings webSettings = wv_detail.getSettings();
        //如果访问的页面中要与Javascript交互，则webview必须设置支持Javascript
        webSettings.setJavaScriptEnabled(true);

        //设置自适应屏幕
        webSettings.setUseWideViewPort(true); //将图片调整到适合webview的大小


        //其他细节操作
        webSettings.setCacheMode(WebSettings.LOAD_NO_CACHE); //关闭webview中缓存
        webSettings.setLoadsImagesAutomatically(true); //支持自动加载图片
        webSettings.setDefaultTextEncodingName("utf-8");//设置编码格式

        // 设置可以支持缩放
        webSettings.setSupportZoom(true);

        //自适应屏幕
        webSettings.setLayoutAlgorithm(WebSettings.LayoutAlgorithm.SINGLE_COLUMN);
        webSettings.setLoadWithOverviewMode(true);

        LogUtil.e("ETTWETWETW",url);
        wv_detail.loadUrl(url);
        wv_detail.setWebViewClient(new WebViewClient(){
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }
        });
    }


}
